
#define _IO               volatile
#define PERIPH_BASE       ((Ulong)0x40000000)
#define APB1PERIPH_BASE   PERIPH_BASE
#define APB2PERIPH_BASE   (PERIPH_BASE + 0x00010000)
#define AHBPERIPH_BASE    (PERIPH_BASE + 0x00020000)
#define RCC_BASE          (AHBPERIPH_BASE + 0x00001000)

// RCC type define
typedef struct {
    _IO Ulong  CR;
    _IO Ulong  CFGR;
    _IO Ulong  CIR;
    _IO Ulong  APB2RSTR;
    _IO Ulong  APB1RSTR;
    _IO Ulong  AHBENR;
    _IO Ulong  APB2ENR;
    _IO Ulong  APB1ENR;
    _IO Ulong  BDCR;
    _IO Ulong  CSR;  
}RCC_TypeDef;

#define RCC               ((RCC_TypeDef *)RCC_BASE)

// GPIO type define
typedef struct {
    _IO Ulong  CRL;
    _IO Ulong  CRH;
    _IO Ulong  IDR;
    _IO Ulong  ODR;
    _IO Ulong  BSRR;
    _IO Ulong  BRR;
    _IO Ulong  LCKR;    
}GPIO_TypeDef;

#define GPIOA_BASE        (APB2PERIPH_BASE + 0x0800)
#define GPIOB_BASE        (APB2PERIPH_BASE + 0x0C00)
#define GPIOC_BASE        (APB2PERIPH_BASE + 0x1000)
#define GPIOD_BASE        (APB2PERIPH_BASE + 0x1400)
#define GPIOE_BASE        (APB2PERIPH_BASE + 0x1800)
#define GPIOF_BASE        (APB2PERIPH_BASE + 0x1C00)
#define GPIOG_BASE        (APB2PERIPH_BASE + 0x2000)

#define GPIOA             ((GPIO_TypeDef *)GPIOA_BASE)
#define GPIOB             ((GPIO_TypeDef *)GPIOB_BASE)
#define GPIOC             ((GPIO_TypeDef *)GPIOC_BASE)
#define GPIOD             ((GPIO_TypeDef *)GPIOD_BASE)
#define GPIOE             ((GPIO_TypeDef *)GPIOE_BASE)
#define GPIOF             ((GPIO_TypeDef *)GPIOF_BASE)
#define GPIOG             ((GPIO_TypeDef *)GPIOG_BASE)

// Speed define
typedef enum {
    GPIO_Input_Mode = 0,    
    GPIO_Speed_10MHz,
    GPIO_Speed_2MHz,
    GPIO_Speed_50MHz
}GPIOSpeed_TypeDef;

// input mode define
typedef enum {
    GPIO_Mode_AIN         = 0x00,
    GPIO_Mode_IN_FLOATING = 0x01,
    GPIO_Mode_IPDPU       = 0x10
}GPIOMode_Input_TypeDef;

